{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0926aca6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在A中，p1: 2 ,p2: 4, p3: 8 \n"
     ]
    }
   ],
   "source": [
    "class A():\n",
    "    def __init__(self,\n",
    "              param1,\n",
    "              param2,\n",
    "              param3):\n",
    "        self.param1 = param1\n",
    "        self.param2 = 2*param2\n",
    "        self.param3 = 4*param3\n",
    "        print('在A中，p1: {} ,p2: {}, p3: {} '.format(self.param1, self.param2, self.param3))\n",
    "\n",
    "a = A(2, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5bf684b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在A中，p1: 2 ,p2: 4, p3: 8 \n",
      "在B中，p4: 2 ,p5: 2 \n"
     ]
    }
   ],
   "source": [
    "class B(A):\n",
    "    def __init__(self,\n",
    "                param6,\n",
    "                param7,\n",
    "                param8,\n",
    "                param4,\n",
    "                param5):\n",
    "        super().__init__(param6, param7, param8)\n",
    "        self.param4 = param4\n",
    "        self.param5 = param5\n",
    "        print('在B中，p4: {} ,p5: {} '.format(self.param4, self.param5))\n",
    "\n",
    "        \n",
    "b = B(2, 2, 2, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "deb9be17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在A中，p1: 2 ,p2: 4, p3: 8 \n",
      "在B中，p4: 2 ,p5: 2 \n",
      "在C中，p1: 2 \n",
      "4\n"
     ]
    }
   ],
   "source": [
    "class C(B):\n",
    "    def __init__(self,\n",
    "                param9,\n",
    "                param10,\n",
    "                param11,\n",
    "                param12,\n",
    "                param13):\n",
    "        super().__init__(param9, param10, param11, param12, param13)\n",
    "        self.param11 = param11\n",
    "        print('在C中，p1: {} '.format(self.param11))\n",
    "        print(self.param2)\n",
    "        \n",
    "c = C(2, 2, 2, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c27b7ba8",
   "metadata": {},
   "outputs": [],
   "source": [
    "class mysum:\n",
    "    def __init__(self,\n",
    "                a,\n",
    "                b):\n",
    "        self.a = a\n",
    "        self.b = b\n",
    "    def forward(self):\n",
    "        print('mysum: answer is {}'.format(self.a+self.b))\n",
    "        \n",
    "class son_of_mysum(mysum):\n",
    "    def __init__(self,\n",
    "                c,\n",
    "                d,\n",
    "                e):\n",
    "        super().__init__(c, d)\n",
    "        self.e = e\n",
    "    def forward_train(self):\n",
    "        res = self(self.a, self.b)\n",
    "        print('sum is {}, another parameter is {}'.format(res, self.e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "206cbc31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method son_of_mysum.forward_train of <__main__.son_of_mysum object at 0x000001DB09FCB580>>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "son = son_of_mysum(1, 2, 3)\n",
    "son.forward_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8a74e0c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
